/*
 * This file is Copyright 2002-2006 Loyola University Chicago,
 * Department of Computer Science and the Emerging Technologies Laboratory.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License via
 *    http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.citep.web.admin.users.client;

import com.citep.web.gwt.module.CitepModule;
import com.citep.web.gwt.module.Presentation;

public class UserEntryModule  implements CitepModule {
	
	private UserEntryApplication application;
	private UserEntryPresentation presentation;

	private static UserEntryModule moduleSingleton;
	
	public static UserEntryModule getInstance() {
		if(moduleSingleton == null) {
			moduleSingleton = new UserEntryModule();
		}
		return moduleSingleton;
	}
	
	public UserEntryModule() {
		presentation = new UserEntryPresentation();
		application = new UserEntryApplication();
		
		presentation.setApplication(application);
		application.setPresentation(presentation);
		
		//populate the role listbox
		application.updateRoleList();
	}


	public Presentation getPresentation() {
		return presentation;
 	}
	
	public UserEntryApplication getApplication() {
		return application;
	}

	public void init(Object param) {
		//if we were sent a user id, set the module to edit-mode and populate the fields
		if(param != null) {
			//TODO: check if parameter is int, or else report invalid parameter
			int userId = ((Integer)param).intValue();
			application.getUser(userId);
		} else {
			presentation.setSaveState();
		}
	}

	public void onHide() {
		// TODO Auto-generated method stub
		
	}

	public void onShow() {
		// TODO Auto-generated method stub
		
	}

}
